package net.xdclass.controller;


import net.xdclass.controller.Request.AccountLoginRequest;
import net.xdclass.controller.Request.AccountRegisterRequest;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.service.AccountService;
import net.xdclass.service.FileService;
import net.xdclass.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2025-07-01
 */
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {
	@Autowired
	FileService fileService;

	@Autowired
	AccountService accountService;

	@PostMapping("/uploadUserImg")
	public JsonData uploadUserImg(@RequestPart("file") MultipartFile file){
		String imgUrl = fileService.uploadUserImg(file);
//		if (imgUrl != null) {
//			return JsonData.buildSuccess(imgUrl);
//		} else {
//			return JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);
//		}
		return imgUrl != null ? JsonData.buildSuccess(imgUrl) : JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);
	}
	@PostMapping("/register")
	public JsonData register(@RequestBody AccountRegisterRequest registerRequest){
		JsonData jsonData = accountService.register(registerRequest);
		return  jsonData;
	}

	@PostMapping("/login")
	public JsonData login(@RequestBody AccountLoginRequest accountLoginRequest){
		JsonData jsonData = accountService.login(accountLoginRequest);
		return  jsonData;
	}
}

